package com.yh.service.impl;

import com.yh.mapper.PermissionMapper;
import com.yh.model.Permission;
import com.yh.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PermissionServiceImpl implements PermissionService {
    @Autowired
    PermissionMapper permissionMapper;

    /**
     * 查询所有权限
     *
     * @return
     */
    @Override
    public List<Permission> findAll() {
        return permissionMapper.findAll();
    }

    /**
     * 根据id查询权限
     *
     * @param pid
     * @return
     */
    @Override
    public Permission findById(String pid) {
        return permissionMapper.findById(pid);
    }

    /**
     * 根据id删除权限
     * @param pid
     */
    @Override
    public void deleteById(String pid) {
        //先删除权限和角色的关系
        permissionMapper.deleteRelationByPermissionId(pid);
        //再删除权限
        permissionMapper.deletePermissionByPermissionId(pid);
    }

    /**
     * 添加权限
     *
     * @param permission
     */
    @Override
    public void save(Permission permission) {
        permissionMapper.save(permission);
    }


}
